home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / panelRender.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  14.5 KB  |  696 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include "gl.h"
  22. #include "math.h"
  23. #include "geom.h"
  24. #include "colors.h"
  25. #include "classIds.h"
  26. #include "objIds.h"
  27.  
  28.     /*
  29.      *  render floor for the master panel
  30.      */
  31. buildFloor(r, id)
  32.     register rectangle *r;
  33.     Object id;
  34. {
  35.     static inited = FALSE;
  36.  
  37.     if (inited) return;
  38.     else inited = TRUE;
  39.  
  40.     makeobj(id);
  41.     fishColor(PANEL_BLACK);
  42.     rectfi(0,0, r->extent.x, r->extent.y);
  43.     fishColor(PANEL_GRAY3);
  44.     cmov2i(10,12);
  45.     charstr("Camera Controls");
  46.     closeobj();
  47. }
  48.  
  49.  
  50. point2d cam1shaftPoints[] = {
  51.     {  0,  0, },    /* gratuitous 0th point */
  52.     {  0,  0, },
  53.     { 25,  2, },
  54.     { 45,  4, },
  55.     { 50,  5, },
  56.     { 66, 10, },
  57.     { 72, 15, },
  58.     { 75, 20, },
  59.     { 75,-10, },
  60.     { 72,-15, },
  61.     { 66,-20, },
  62.     { 50,-25, },
  63.     { 25,-28, },
  64.     {  0,-30, },
  65. };
  66.         /* null terminated polys, double null at end */
  67. long cam1shaftVertices[] = {
  68.     1,2,12,13,0,
  69.     2,3,4,11,12,0,
  70.     4,5,10,11,0,
  71.     5,6,9,10,0,
  72.     6,7,8,9,0,
  73.     0,
  74. };
  75.  
  76. point2d cam1headPoints[] = {
  77.     {  0,  0, },    /* gratuitous 0th point */
  78.     { 45,  4, },
  79.     { 35, 17, },
  80.     { 55, 43, },
  81.     { 55, 33, },
  82.     { 66, 30, },
  83.     { 72, 25, },
  84.     { 75, 20, },
  85.     { 72, 15, },
  86.     { 66, 10, },
  87.     { 50,  5, },
  88. };
  89.         /* null terminated polys, double null at end */
  90. long cam1headVertices[] = {
  91.     1,2,3,4,0,
  92.     1,4,5,6,7,8,9,10,0,
  93.     0,
  94. };
  95.  
  96.  
  97.     /*
  98.      *  render camera left-right valuator
  99.      */
  100. buildCam1(r, id)
  101.     register rectangle *r;
  102.     Object id;
  103. {
  104.     static inited = FALSE;
  105.  
  106.     if (inited) return;
  107.     else inited = TRUE;
  108.  
  109.     makeobj(CAM1PART1);
  110.     fishColor(PANEL_GRAY5);
  111.     drawpolys(cam1shaftPoints, cam1shaftVertices);
  112.     fishColor(PANEL_BLACK);
  113.     drawpolys(cam1headPoints, cam1headVertices);
  114.     closeobj();
  115.  
  116.     makeobj(id);
  117.     pushmatrix();
  118.     fishColor(PANEL_GRAY3);
  119.     rectfi(0,0, r->extent.x,r->extent.y);
  120.     fishColor(REAL_BLACK);
  121.     recti(0,0, r->extent.x,r->extent.y);
  122.  
  123.     translate((float)(r->extent.x/2), (float)(r->extent.y/2), 0.0);
  124.     scale(0.95, -0.95, 1.0);
  125.     callobj(CAM1PART1);
  126.     pushmatrix();
  127.         scale(-1.0, 1.0, 1.0);
  128.         callobj(CAM1PART1);
  129.     popmatrix();
  130.     pushmatrix();
  131.         rotate(900, 'z');
  132.         callobj(CAM1PART1);
  133.         pushmatrix();
  134.         scale(-1.0, 1.0, 1.0);
  135.         callobj(CAM1PART1);
  136.         popmatrix();
  137.     popmatrix();
  138.     popmatrix();
  139.     closeobj();
  140. }
  141.  
  142. point2d cam2Points[] = {
  143.     {  0,  0, },    /* gratuitous 0th point */
  144.     { 21, 10, },
  145.     {  4, 20, },
  146.     { 16, 20, },
  147.     { 28, 20, },
  148.     { 40, 20, },
  149.     {  1,120, },
  150.     { 16,120, },
  151.     { 45,120, },
  152.     { 60,120, },
  153.     { 34,140, },
  154. };
  155.         /* null terminated polys, double null at end */
  156. long cam2Vertices[] = {
  157.     1,2,3,4,5,0,
  158.     3,4,8,7,0,
  159.     6,7,8,9,10,0,
  160.     0,
  161. };
  162.  
  163.  
  164.     /*
  165.      *  render camera zoom valuator
  166.      */
  167. buildCam2(r, id)
  168.     register rectangle *r;
  169.     Object id;
  170. {
  171.     static inited = FALSE;
  172.  
  173.     if (inited) return;
  174.     else inited = TRUE;
  175.  
  176.     makeobj(CAM2PART1);
  177.     drawpolys(cam2Points, cam2Vertices);
  178.     closeobj();
  179.  
  180.     makeobj(id);
  181.     pushmatrix();
  182.     fishColor(PANEL_GRAY3);
  183.     pmv2i(0,0); pdr2i(38,0);
  184.     pdr2i(r->extent.x,r->extent.y); pdr2i(0,r->extent.y);
  185.     pclos();
  186.  
  187.     pushmatrix();
  188.         fishColor(PANEL_BLACK);
  189.         translate(-2.0, 2.0, 0.0);
  190.         scale(1.0, 1.05, 1.0);
  191.         callobj(CAM2PART1);
  192.     popmatrix();
  193.     pushmatrix();
  194.         fishColor(PANEL_GRAY5);
  195.         translate(2.0, 0.0, 0.0);
  196.         callobj(CAM2PART1);
  197.     popmatrix();
  198.  
  199.     fishColor(REAL_BLACK);
  200.     move2i(0,0); draw2i(38,0);
  201.     draw2i(r->extent.x,r->extent.y); draw2i(0,r->extent.y);
  202.     draw2i(0,0);
  203.     popmatrix();
  204.     closeobj();
  205. }
  206.  
  207.  
  208.     /*
  209.      *  render camera "HOME" button
  210.      */
  211. buildCam3(r, id, hid)
  212.     register rectangle *r;
  213.     Object id, hid;
  214. {
  215.     static inited = FALSE;
  216.  
  217.     if (inited) return;
  218.     else inited = TRUE;
  219.  
  220.     makeobj(id);
  221.     fishColor(PANEL_BLACK);
  222.     rectfi(0,0, r->extent.x, r->extent.y);
  223.     fishColor(PANEL_GRAY5);
  224.     cmov2i(2,10);
  225.     charstr("HOME");
  226.     closeobj();
  227.     makeobj(hid);
  228.     fishColor(PANEL_GRAY5);
  229.     recti(0,0, r->extent.x, r->extent.y);
  230.     cmov2i(2,10);
  231.     charstr("HOME");
  232.     closeobj();
  233. }
  234.  
  235.     /*
  236.      *  render sophistication valuator
  237.      */
  238. buildSoph(r, id, hid)
  239.     register rectangle *r;
  240.     Object id, hid;
  241. {
  242.     char *str;
  243.     static inited = FALSE;
  244.  
  245.     if (inited) return;
  246.     else inited = TRUE;
  247.  
  248.     makeobj(id);
  249.     fishColor(PANEL_GRAY3);
  250.     rectfi(0,0, r->extent.x, r->extent.y);
  251.     fishColor(REAL_BLACK);
  252.     recti(0,0, r->extent.x, r->extent.y);
  253.     fishColor(PANEL_GRAY5);
  254.     cmov2i(4,12);
  255.     charstr("Sophisticated");
  256.     str = "Popular";
  257.     cmov2i(r->extent.x - 4 - strwidth(str),12);
  258.     charstr(str);
  259.     closeobj();
  260.     makeobj(hid);
  261.     fishColor(PANEL_WHITE);
  262.     pmv2i(0,0);
  263.     pdr2i(4, 10);
  264.     pdr2i(-4,10);
  265.     pclos();
  266.     closeobj();
  267. }
  268.  
  269.     /*
  270.      *  build a plain vanilla absolute valuator consisting of a box
  271.      *  containing a sliding bar, and a label below it.
  272.      */
  273. bldVanillaVal(r, id, tid, str)
  274.     register rectangle *r;
  275.     Object id,        /* id of compiled object for painter */
  276.            tid;        /* id of compiled object for tracker */
  277.     char *str;        /* label below valuator */
  278. {
  279.     point2d extent;
  280.  
  281.     makeobj(id);
  282.     extent.x = max(r->extent.x, strwidth(str));
  283.     extent.y = max(6, r->extent.y - getheight());
  284.     fishColor(PANEL_GRAY3);
  285.     rectfi(0,0, extent.x, extent.y);
  286.     fishColor(REAL_BLACK);
  287.     recti(0,0, extent.x, extent.y);
  288.     fishColor(PANEL_GRAY5);
  289.     cmov2i(0, r->extent.y);
  290.     charstr(str);
  291.     closeobj();
  292.  
  293.     r->extent = extent;
  294.     makeobj(tid);
  295.     fishColor(PANEL_WHITE);
  296.     rectfi(-(extent.x>>1)+2,-1, (extent.x>>1)-2, 1);
  297.     closeobj();
  298. }
  299.  
  300.     /*
  301.      *  render individual's control panel floor
  302.      */
  303. buildIndFloor(r, id)
  304.     register rectangle *r;
  305.     Object id;
  306. {
  307.     static inited = FALSE;
  308.  
  309.     if (inited) return;
  310.     else inited = TRUE;
  311.  
  312.     makeobj(id);
  313.     fishColor(PANEL_BLACK);
  314.     rectfi(0,0, r->extent.x, r->extent.y);
  315.     closeobj();
  316. }
  317.  
  318.     /*
  319.      *  render individual's scaling valuator
  320.      */
  321. buildIndSize(r, clientClass, id, tid)
  322.     register rectangle *r;
  323.     int clientClass;
  324.     Object id, tid;
  325. {
  326.     static inited = FALSE;
  327.  
  328.     makeobj(id);
  329.     fishColor(PANEL_GRAY3);
  330.     rectfi(0,0, r->extent.x, r->extent.y);
  331.     fishColor(PANEL_BLACK);
  332.     move2i(0,0); 
  333.     draw2i(r->extent.x-12, r->extent.y);
  334.     draw2i(r->extent.x-12, 0);
  335.     fishColor(REAL_BLACK);
  336.     recti(0,0, r->extent.x, r->extent.y);
  337.     fishColor(PANEL_GRAY5);
  338.     drawfish(clientClass, 0.045, r->extent.x -18, 20);
  339.     drawfish(clientClass, 0.015, r->extent.x -12, r->extent.y-16);
  340.     
  341.     /*
  342.     fishColor(PANEL_GRAY5);
  343.     cmov2i(12,18);
  344.     charstr("Size");
  345.     */
  346.     closeobj();
  347.  
  348.     if (!inited) {
  349.     inited = TRUE;
  350.  
  351.     makeobj(tid);
  352.         fishColor(PANEL_WHITE);
  353.         pmv2i(15,0);
  354.         pdr2i(24, 5);
  355.         pdr2i(24, -5);
  356.         pclos();
  357.     closeobj();
  358.     }
  359. }
  360.  
  361.     /*
  362.      *  render individual's heading controls
  363.      */
  364. /* ARGSUSED */
  365. buildIndHeading(r, clientClass, id, tid)
  366.     register rectangle *r;
  367.     int clientClass;
  368.     Object id, tid;
  369. {
  370.     char *str;
  371.     static inited = FALSE;
  372.  
  373.     if (!inited) {
  374.     inited = TRUE;
  375.  
  376.     makeobj(INDSUBHEAD);
  377.         fishColor(PANEL_GRAY3);
  378.         arcfi(60, 130, 130, -1200, -600);
  379.         fishColor(PANEL_BLACK);
  380.         arcfi(60, 130, 65, -1210, -590);
  381.         fishColor(REAL_BLACK);
  382.         arci(60, 130, 130, -1200, -600);
  383.         arci(60, 130, 65, -1210, -590);
  384.         move2i(93, 74); draw2i(125, 18);
  385.         move2i(27, 74); draw2i( -5, 18);
  386.  
  387.         fishColor(PANEL_GRAY5);
  388.         str = "Direction";
  389.         cmov2i(60-(strwidth(str)/2), 18);
  390.         charstr(str);
  391.     closeobj();
  392.     }
  393.  
  394.     makeobj(id);
  395.     callobj(INDSUBHEAD);
  396.     /****
  397.     fishColor(PANEL_GRAY3);
  398.     if (clientClass == GUPPY) {
  399.         str = "Guppy Controls";
  400.     }
  401.     else if (clientClass == MINNOW) {
  402.         str = "Minnow Controls";
  403.     }
  404.     else str = "Fish Controls";
  405.     cmov2i(60-(strwidth(str)/2), 90);
  406.     charstr(str);
  407.     *****/
  408.     closeobj();
  409.  
  410.     makeobj(tid);
  411.     fishColor(PANEL_WHITE);
  412.     circfi(0,0,5);
  413.     closeobj();
  414. }
  415.  
  416. point2d guppySidePoints[] = {
  417.     {  0,  0, },    /* gratuitous 0th point */
  418.     {  600,   000, },
  419.     {  000,   000, },
  420.     {  150,  -320, },
  421.     {  300,  -320, },
  422.     {  510,  -250, },
  423.     {  590,  -150, },
  424.         /* tail */
  425.     {  100,  -200, },
  426.     { -200,   400, },
  427.     { -200,  -500, },
  428. };
  429.         /* null terminated polys, double null at end */
  430. long guppySideVertices[] = {
  431.     1,2,3,4,5,6,0,
  432.     7,8,9,0,
  433.     0,
  434. };
  435.  
  436. point2d minnowSidePoints[] = {
  437.     {  0,  0, },    /* gratuitous 0th point */
  438.     {  000,  000, },
  439.     {  200, -300, },
  440.     {  730, -130, },
  441.     {  710, -100, },
  442.     {  750, -030, },
  443.     {  300,  300, },
  444.     /* tail */
  445.     {  000,  000, },
  446.     { -300,  400, },
  447.     { -300, -550, },
  448. };
  449.         /* null terminated polys, double null at end */
  450. long minnowSideVertices[] = {
  451.     1,2,3,4,5,6,0,
  452.     7,8,9,0,
  453.     0,
  454. };
  455.  
  456.  
  457.     /*
  458.      *  render individual's azimuth valuator
  459.      */
  460. buildIndAzimuth(r, clientClass, id, tid)
  461.     register rectangle *r;
  462.     int clientClass;
  463.     Object id, tid;
  464. {
  465.     int i, rad;
  466.     static inited = FALSE;
  467.  
  468.     if (!inited) {
  469.     inited = TRUE;
  470.  
  471.     makeobj(id);
  472.         fishColor(PANEL_GRAY3);
  473.         rectfi(0,0, r->extent.x, r->extent.y);
  474.         fishColor(REAL_BLACK);
  475.         recti(0,0, r->extent.x, r->extent.y);
  476.         /* top edge (waves) */
  477.         rad = r->extent.x/6 + 1;
  478.         for (i=rad-1; i<= r->extent.x - rad+6; i += 2*(rad-1)) {
  479.         fishColor(PANEL_BLACK);
  480.         arcfi(i, -4, rad, 0, 1800);
  481.         }
  482.         /* bottom edge (pebbles) */
  483.         rad = r->extent.x/12;
  484.         for (i=rad+1; i<= r->extent.x - 3; i += 2*rad) {
  485.         fishColor(PANEL_BLACK);
  486.         arcfi(i, r->extent.y + (i % 3) + 2, rad + (i % 2), 1800, 3600);
  487.         }
  488.         /*
  489.         fishColor(PANEL_GRAY5);
  490.         cmov2i(12,18);
  491.         charstr("Rise");
  492.         */
  493.     closeobj();
  494.     }
  495.  
  496.     makeobj(tid);
  497.     fishColor(PANEL_WHITE);
  498.     drawfish(clientClass, 0.03, 6,0);
  499.     closeobj();
  500. }
  501.  
  502.  
  503.     /*
  504.      *  render individual's speed valuator
  505.      */
  506. buildIndSpeed(r, clientClass, id, tid)
  507.     register rectangle *r;
  508.     int clientClass;
  509.     Object id, tid;
  510. {
  511.     int i;
  512.     static inited = FALSE;
  513.  
  514.     if (!inited) {
  515.     inited = TRUE;
  516.  
  517.     makeobj(id);
  518.         fishColor(PANEL_GRAY3);
  519.         rectfi(0,0, r->extent.x, r->extent.y);
  520.         fishColor(REAL_BLACK);
  521.         recti(0,0, r->extent.x, r->extent.y);
  522.     closeobj();
  523.     }
  524.     makeobj(tid);
  525.     fishColor(PANEL_WHITE);
  526.     drawfish(clientClass, 0.02, 0,0);
  527.  
  528.     fishColor(PANEL_GRAY5);
  529.     move2i(10, 0);
  530.     for (i=0; i<r->extent.x - 10; i+=3) {
  531.         draw2i(i+10, (int)(3.0 * sin((float)(i)*0.3)));
  532.     }
  533.     closeobj();
  534. }
  535.  
  536.     /*
  537.      *  render individual's snuff button
  538.      */
  539. buildIndSnuff(r, clientClass, id, tid)
  540.     register rectangle *r;
  541.     int clientClass;
  542.     Object id, tid;
  543. {
  544.     char *str;
  545.  
  546.     makeobj(id);
  547.     pushmatrix();
  548.         fishColor(PANEL_GRAY3);
  549.         rectfi(0,0, r->extent.x, r->extent.y);
  550.         fishColor(REAL_BLACK);
  551.         recti(0,0, r->extent.x, r->extent.y);
  552.         fishColor(PANEL_GRAY5);
  553.         /* drawfish(clientClass, -0.04, r->extent.x/2-5, r->extent.y/2);/**/
  554.         drawfish(clientClass, -0.025, r->extent.x/2-5, r->extent.y/2);
  555.         fishColor(PANEL_BLACK);
  556.         linewidth(2);
  557.         /***
  558.         move2i(r->extent.x/2-15, r->extent.y/2-15);
  559.         draw2i(r->extent.x/2+15, r->extent.y/2+15);
  560.         move2i(r->extent.x/2+15, r->extent.y/2-15);
  561.         draw2i(r->extent.x/2-15, r->extent.y/2+15);
  562.         ****/
  563.         move2i(r->extent.x/2-10, r->extent.y/2-10);
  564.         draw2i(r->extent.x/2+10, r->extent.y/2+10);
  565.         move2i(r->extent.x/2+10, r->extent.y/2-10);
  566.         draw2i(r->extent.x/2-10, r->extent.y/2+10);
  567.         linewidth(1);
  568.         popmatrix();
  569.     /**************
  570.     str = "Expire";
  571.     cmov2i(r->extent.x/2 - strwidth(str)/2, r->extent.y-10);
  572.     charstr(str);
  573.     /**************/
  574.     closeobj();
  575.  
  576.     makeobj(tid);
  577.     fishColor(PANEL_GRAY5);
  578.     str = "Expire";
  579.     cmov2i(r->extent.x/2 - strwidth(str), r->extent.y-5);
  580.     charstr(str);
  581.     closeobj();
  582. }
  583.  
  584.  
  585.     /*
  586.      *  render test menu
  587.      */
  588. buildMenu1(r, nbuttons, id, tid)
  589.     register rectangle *r;
  590.     point2d *nbuttons;
  591.     Object id, tid;
  592. {
  593.     makeobj(id);
  594.     fishColor(PANEL_GRAY3);
  595.     rectfi(0,0, r->extent.x, r->extent.y);
  596.     fishColor(REAL_BLACK);
  597.     recti(0,0, r->extent.x, r->extent.y);
  598.     closeobj();
  599.     makeobj(tid);
  600.     fishColor(PANEL_GRAY5);
  601.     recti(0,0, r->extent.x/nbuttons->x, r->extent.y/nbuttons->y);
  602.     popmatrix();
  603.     closeobj();
  604. }
  605.  
  606.  
  607.     /*
  608.      *  render individual's color valuator set
  609.      */
  610. /* ARGSUSED */
  611. buildCol(r, clientColor, id1, id2, tid)
  612.     register rectangle *r;
  613.     int clientColor;
  614.     Object id1, id2, tid;
  615. {
  616.     static point2d box1, box2;
  617.     static inited = FALSE;
  618.  
  619.     if (!inited) {
  620.     inited = TRUE;
  621.  
  622.     setpt2d(&box2, (r->extent.x-10)/4, r->extent.y);
  623.     setpt2d(&box1, 3*box2.x, r->extent.y);
  624.  
  625.     makeobj(id1);
  626.         fishColor(RED);
  627.         rectfi(0, 0,          box1.x/3, 10);
  628.         rectfi(0,box1.y - 10, box1.x/3, box1.y);
  629.         fishColor(GREEN);
  630.         rectfi(box1.x/3, 0,         (2*box1.x)/3, 10);
  631.         rectfi(box1.x/3, box1.y-10, (2*box1.x)/3, box1.y);
  632.         fishColor(BLUE);
  633.         rectfi((2*box1.x)/3, 0,        box1.x, 10);
  634.         rectfi((2*box1.x)/3, box1.y-10, box1.x, box1.y);
  635.     closeobj();
  636.     makeobj(id1);
  637.         fishColor(BLACK);
  638. /*        rectfi(box1.x+10, 0, box2.x, 10); /* */
  639.         rectfi(0, 0, box2.x, 10);
  640.         fishColor(WHITE);
  641. /*        rectfi(box1.x+10, 10, box2.x, box2.y); /* */
  642.         rectfi(0, 10, box2.x, box2.y);
  643.     closeobj();
  644.     }
  645.     makeobj(tid);
  646.     fishColor(clientColor);
  647.     rectfi(0,10, box1.x, box1.y-20);
  648.     rectfi(box1.x+10, 10, box2.x, box2.y-20);
  649. /*    rectfi(box1.x+10, 10, box2.x, box2.y); /* */
  650.     closeobj();
  651. }
  652.  
  653.  
  654.  
  655. drawfish(clientClass, size, x,y)
  656.     int clientClass;
  657.     float size;
  658.     int x,y;
  659. {
  660.     pushmatrix();
  661.     translate((float)x, (float)y, 0.0);
  662.     if (clientClass == GUPPY) {
  663.         scale(-(size*1.1), -(size*1.1), size);
  664.         drawpolys(guppySidePoints, guppySideVertices);
  665.     }
  666.     else if (clientClass == MINNOW) {
  667.         scale(-(size*0.9), -size, size);
  668.         drawpolys(minnowSidePoints, minnowSideVertices);
  669.     }
  670.     else {
  671.         circfi(0, 0, 6);
  672.     }
  673.     popmatrix();
  674. }
  675.  
  676.     /*
  677.      * draw 2d polygon from a point dictionary and vertex list
  678.      */
  679. drawpolys(pnts, verts)
  680.     register point2d *pnts;
  681.     register long *verts;
  682. {
  683.     register point2d *p;
  684.  
  685.     while(*verts) {
  686.     p = &pnts[*(verts++)];
  687.     pmv2i(p->x, p->y);
  688.     while(*verts) {
  689.         p = &pnts[*(verts++)];
  690.         pdr2i(p->x, p->y);
  691.     }
  692.     pclos();
  693.     verts++;
  694.     }
  695. }
  696.